<include file="Public/min-header" />
<div class="wrapper">
    <include file="Public/breadcrumb" />
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><i class="fa fa-list"></i> 优惠券列表</h3>
                    </div>
                    <div class="panel-body">
                        <div class="navbar navbar-default">
                            <form class="navbar-form form-inline" action="" method="post">
                                <!--
                                                    <div class="form-group">
                                                        <input type="text" class="form-control" placeholder="搜索">
                                                    </div>
                                                    <button type="submit" class="btn btn-primary">提交</button>
                                -->
                                <div class="form-group pull-right">
                                    <a href="{:U('Admin/Coupon/couponInfo')}" class="btn btn-primary pull-right"><i class="fa fa-plus"></i>添加优惠券</a>
                                </div>
                            </form>
                        </div>
                        <div id="ajax_return">
                            <div class="table-responsive">
                                <table class="table table-bordered table-hover">
                                    <thead>
                                        <tr>
                                            <th style="width: 1px;" class="text-center">
                                                <input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);">
                                            </th>
                                            <th class="text-center">优惠券名称</th>
                                            <th class="text-center">优惠券类型</th>
                                            <th class="text-center">面额</th>
                                            <th class="text-center">使用需满金额</th>
                                            <th class="text-center">发放总量</th>
                                            <th class="text-center">已发放数</th>
                                            <th class="text-center">已使用</th>
                                            <th class="text-center">使用截止日期</th>
                                            <th class="text-center">操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <volist name="lists" id="list">
                                            <tr>
                                                <td class="text-center">
                                                    <input type="checkbox" name="selected[]" value="6">
                                                </td>
                                                <td class="text-left">{$list.name}</td>
                                                <td class="text-left">{$coupons[$list[type]]}</td>
                                                <td class="text-right">{$list.money}</td>
                                                <td class="text-right">{$list.condition}</td>
                                                <td class="text-left">{$list.createnum}</td>
                                                <td class="text-left">{$list.send_num}</td>
                                                <td class="text-left">{$list.use_num}</td>
                                                <td class="text-center">{$list.use_end_time|date='Y-m-d',###}</td>
                                                <td class="text-left">
                                                    <if condition="$list[type] eq 4">
                                                        <a href="{:U('Admin/Coupon/makeCoupon',array('id'=>$list['id'],'type'=>$list['type']))}" data-toggle="tooltip" title="" class="btn btn-info" data-original-title="发放"><i class="fa fa-send"></i></a>
                                                        <elseif condition="$list[type] eq 1" />
                                                        <a href="javascript:;" data-toggle="tooltip" title="发放" class="btn btn-info send_user" data-url="{:U('Coupon/sendCoupon',array('cid'=>$list[id]))}"><i class="fa fa-send-o"></i></a>
                                                        <else/>
                                                        <a href="javascript:;" data-toggle="tooltip" title="" class="btn btn-primary disabled" data-original-title="查看"><i class="fa fa-send-o"></i></a>
                                                    </if>
                                                    <a href="{:U('Admin/Coupon/couponList',array('id'=>$list['id']))}" data-toggle="tooltip" title="" class="btn btn-info" data-original-title="查看"><i class="fa fa-eye"></i></a>
                                                    <a href="{:U('Admin/Coupon/couponInfo',array('id'=>$list['id']))}" data-toggle="tooltip" title="" class="btn btn-info" data-original-title="编辑"><i class="fa fa-pencil"></i></a>
                                                    <a data-url="{:U('Admin/Coupon/delCoupon',array('id'=>$list['id']))}" onclick="delfun(this)" href="javascript:;" data-toggle="tooltip" title="" class="btn btn-danger" data-original-title="删除"><i class="fa fa-trash-o"></i></a></td>
                                            </tr>
                                        </volist>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-6 text-left"></div>
                            <div class="col-sm-6 text-right">{$page}</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- /.row -->
    </section>
</div>
<script>
$('.send_user').click(function() {
    var url = $(this).attr('data-url');
    layer.open({
        type: 2,
        title: '发放优惠券',
        shadeClose: true,
        shade: 0.5,
        area: ['70%', '85%'],
        content: url
    });
});

function delfun(obj) {
    if (confirm('确认删除')) {
        $.ajax({
            type: 'post',
            url: $(obj).attr('data-url'),
            dataType: 'json',
            success: function(data) {
                if (data) {
                    $(obj).parent().parent().remove();
                } else {
                    layer.alert('删除失败', {
                        icon: 2
                    });
                }
            }
        });
    }
    return false;
}
</script>
</body>

</html>
